package com.ruoyi.exam.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamTimeSlot;
import com.ruoyi.exam.service.IExamTimeSlotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 时间片段管理Controller
 * 
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/exam/timeSlot")
public class ExamTimeSlotController extends BaseController
{
    @Autowired
    private IExamTimeSlotService examTimeSlotService;

    /**
     * 查询时间片段管理列表
     */
    @PreAuthorize("@ss.hasPermi('exam:timeSlot:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamTimeSlot examTimeSlot)
    {
        startPage();
        List<ExamTimeSlot> list = examTimeSlotService.selectExamTimeSlotList(examTimeSlot);
        return getDataTable(list);
    }

    /**
     * 导出时间片段管理列表
     */
    @PreAuthorize("@ss.hasPermi('exam:timeSlot:export')")
    @Log(title = "时间片段管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamTimeSlot examTimeSlot)
    {
        List<ExamTimeSlot> list = examTimeSlotService.selectExamTimeSlotList(examTimeSlot);
        ExcelUtil<ExamTimeSlot> util = new ExcelUtil<ExamTimeSlot>(ExamTimeSlot.class);
        util.exportExcel(response, list, "时间片段管理数据");
    }

    /**
     * 获取时间片段管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:timeSlot:query')")
    @GetMapping(value = "/{timeId}")
    public AjaxResult getInfo(@PathVariable("timeId") Long timeId)
    {
        return success(examTimeSlotService.selectExamTimeSlotByTimeId(timeId));
    }

    /**
     * 新增时间片段管理
     */
    @PreAuthorize("@ss.hasPermi('exam:timeSlot:add')")
    @Log(title = "时间片段管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamTimeSlot examTimeSlot)
    {
        return toAjax(examTimeSlotService.insertExamTimeSlot(examTimeSlot));
    }

    /**
     * 修改时间片段管理
     */
    @PreAuthorize("@ss.hasPermi('exam:timeSlot:edit')")
    @Log(title = "时间片段管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamTimeSlot examTimeSlot)
    {
        return toAjax(examTimeSlotService.updateExamTimeSlot(examTimeSlot));
    }

    /**
     * 删除时间片段管理
     */
    @PreAuthorize("@ss.hasPermi('exam:timeSlot:remove')")
    @Log(title = "时间片段管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{timeIds}")
    public AjaxResult remove(@PathVariable Long[] timeIds)
    {
        return toAjax(examTimeSlotService.deleteExamTimeSlotByTimeIds(timeIds));
    }
}
